<?php
/** 
 * Created by RisingSun. 
 * User: MarkSpace 
 * Date: 20210822
 * Time: 11:05 
 * 列表管理
 */
namespace app\settle\model;

use  app\settle\model\Model;
use  app\settle\model\Common;

class Recharge extends Model{
	
    private $account = 'user_account'; // 账户表
    private $role = 'sys_role';
    private $recharge = 'user_recharge'; // 充值表
    

    private $error=['code'=>0,'msg'=>'fail'];
    private $success=['code'=>200,'msg'=>'success']; 

    /**
     *  账户列表
     * @param array $list 
     * @param array $where 
     */ 
    public function list($where=null,$page=1,$page_size=10){
        //列表
        $list['datalist']= Model::name($this->account)
            ->alias('a')
            ->join($this->role.' b','a.roletype=b.id', 'left')
            ->field(' a.*, b.title as type')
            ->where($where)
            ->limit(($page-1)*$page_size,$page_size)
            ->select()
            ->toArray();
        //数据总数
        $list['total']=Model::name($this->account)
            ->alias('a')
            ->where($where)
            ->count('a.aid');
        return $list;
    }

    /**
     * 充值列表
     * @param array $rechargelist 
     * @param array $where 
     */ 
    public function rechargelist($where=null,$page=1,$page_size=10){
        //列表
        $list['datalist']= Model::name($this->recharge)
            ->alias('a')
            ->join($this->account.' b','a.aid=b.aid','left')
            ->field('a.*,b.realname,b.username')
            ->limit(($page-1)*$page_size,$page_size)
            ->order('id desc')
            ->where($where)
            ->select()
            ->toArray();
        //数据总数
        $list['total']=Model::name($this->recharge)
            ->alias('a')
            ->where($where)
            ->count('a.id');
        return $list;
    }

    /**
     * 充值信息
     * @param array $rechargeinfo 
     * @param array $where 
     */ 
    public function rechargeinfo($where=null,$file='*'){  
        $info=Model::name($this->recharge)
           ->alias('a')
           ->field($file)
           ->where($where)
           ->find();
        return $info;
    }


    /**
     * 账户信息
     * @param array $info 
     * @param array $where 
     */ 
    public function info($id=null,$field='*'){  
         return Model::name($this->account)
           ->field($field)
           ->where(['aid'=>$id])
           ->find();;
    }

}
